<template>
    <div class="shop-num">
        <div @click="addnum++">+</div>
        <div>{{addnum}}</div>
        <div @click="reds">-</div>
    </div>
</template>

<script>
const counter = {
	addnum: 1
};
export default {
    name: 'Addnums',
    // 复制addmuns，让组件有可复用性
    data() {
		const newCounter = Object.assign({}, counter);
		return newCounter;
    },
    methods: {
        // 让数字不可小于1
        reds() {
            if(this.addnum > 1) {
                this.addnum--
            }
        }
    }
}
</script>

<style scoped>
    .shop-num {
        display: flex;
        width: 80px;
        float: right;
        height: 50px;
        margin-right: 20px;
    }
    .shop-num div {
        height: 25px;
        font-size: 20px;
        margin: 11.5px 0;
    }
    .shop-num div:nth-child(1) {
        width: 20px;
        border: #a1a1a1 solid 1px;
        text-align: center;
        line-height: 27px;
    }
    .shop-num div:nth-child(2) {
        width: 30px;
        border-top: #a1a1a1 solid 1px;
        border-bottom: #a1a1a1 solid 1px;
        text-align: center;
        line-height: 27px;
    }
    .shop-num div:nth-child(3) {
        width: 20px;
        border: #a1a1a1 solid 1px;
        text-align: center;
        line-height: 20px;
    }
</style>